**************************************
*generated: 2024-07-18
*
*by Lukas Rudolph 
*
*Data used:  w4_final_recoded_local
*Data output generated: 
	*rologit1.dta, rologit2.dta, rologit3.dta, rologit4.dta
	*separatepartyfourgroup1.dta, separatepartyfourgroup2.dta, separatepartyfourgroup3.dta,separatepartyfourgroup4.dta
*Tables generated: Appendix Tables A.3-A.7
*Figutes generated: none
**************************************

*specify version
version 17

*load packages if not already installed
* findit estout // by Benn Jann

*set working directory to path containing replication data files
cd ""

*load data
use w4_final_reshaped.dta, clear
 
 
**************************************************
*APPENDIX TABLES
**************************************************

********************
** Estimate models for Figures 3 and 4 and Appendix Tables A.3-4  
********************
// note: this takes very, very long to run, >120 hours on a normal machine; recommendation: run remotely via a remote desktop connection, if available

eststo clear

forval i = 1/4 {
eststo m`i': cmrologit w4_q33x  partyidmatch localitymatch gendermatch  i.agematch2 i.displayplace i.w4_listplace_cand_cat ///
 c.lr_diff c.env_score_diff  i.w4_partyid_candv2 ,  incomplete(0)  ties(exactm) vce(bootstrap, cluster(pubid) reps(500) seed(231009)) ///
 , if w4_treat6 ==  `i'
}


** Data export for figure 3 and 4 production

preserve
forval i = 1/4 {
clear
est restore m`i'
matrix B = e(b)',e(V)
svmat B
save "data/rologit`i'.dta", replace
}
restore


*********** Appendix Table A.3 

 esttab  ///  using "tabA3.tex" /// 
, replace noomitted label nobase se stats(N r2_p) ///
order(*env_score_diff* *lr_diff* *localitymatch* *gendermatch* *agematch2* *place* *partyid* ) star(+ 0.1 * 0.05 ** 0.01 *** 0.001) ///
mgroups("control" "env" "lr" "lr \& env" , pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span)


*********** Appendix Table A.4

 esttab  ///  using "tabA4.tex" /// 
, eform replace noomitted label nobase se stats(N r2_p) ///
order(*env_score_diff* *lr_diff* *localitymatch* *gendermatch* *agematch2* *place* *partyid* ) star(+ 0.1 * 0.05 ** 0.01 *** 0.001) ///
mgroups("control" "env" "lr" "lr \& env" , pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span)



********************
** Estimate models for Appendix Tables A.5
********************

eststo clear

foreach x in 1 2 3 4 {
eststo: cmrologit w4_q33x partyidmatch urbanlocalitymatch periurbanlocalitymatch rurallocalitymatch  malegendermatch  femalegendermatch i.youngagematch2 i.oldagematch2  i.displayplace i.w4_listplace_cand_cat ///
 c.lr_diff c.env_score_diff  i.w4_partyid_candv2 , incomplete(0)  ties(exactm) vce(oim), if w4_treat6 == `x' 
}


*********** Appendix Table A.5

 esttab  /// using "tabA5.tex" /// 
, replace noomitted label nobase se stats(N r2_p) ///
order(*env_score_diff* *lr_diff* *urbanlocalitymatch* *periurbanlocalitymatch* *rurallocalitymatch*  *malegendermatch*  *femalegendermatch* *youngagematch2* *oldagematch2* *place* *partyid* ) star(+ 0.1 * 0.05 ** 0.01 *** 0.001) ///
mgroups("control" "env" "lr" "lr \& env" , pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span)



********************
** Estimate models for Appendix Table A.6
********************
// note: this takes very, very long to run, >120 hours on a normal machine; recommendation: run remotely via a remote desktop connection, if available

eststo clear

eststo: cmrologit w4_q33x  (partyidmatch localitymatch gendermatch i.agematch2  i.displayplace i.w4_listplace_cand_cat ///
c.lr_diff c.env_score_diff  i.w4_partyid_candv2)##i.w4_treat6_cor, incomplete(0)  ties(exactm) vce(bootstrap, cluster(pubid) strata(w4_treat6_cor) reps(500) seed(231009)) trace


*********** Appendix Table A.6: 

esttab /// using "tabA6.tex" /// 
, replace noomitted label nobase se stats(N r2_p) ///
order(*env_score_diff* *lr_diff* *localitymatch* *gendermatch* *agematch2* *place* *partyid* ) star(+ 0.1 * 0.05 ** 0.01 *** 0.001)




********************
** Estimate models for Figures A.6 and A.7 and Appendix Table A.7
********************

eststo clear

foreach x in 1 2 3 4 {
eststo: cmrologit w4_q33x partyidmatch localitymatch gendermatch  i.agematch2 i.displayplace i.w4_listplace_cand_cat ///
c.canddiff_partydiff_lr c.canddiff_partydiff_env c.partymean_lr_diff c.partymean_env_diff  i.w4_partyid_candv2 , incomplete(0)  ties(exactm) vce(oim) ///
 , if w4_treat6 ==  `x'
 
** Data export for figure A.6 and A.7 production
preserve
clear
matrix B = e(b)',e(V)
svmat B
save "separatepartyfourgroup`x'.dta", replace
restore
}


*********** Appendix Table A.7

 esttab /// using "tabA7.tex" /// 
, replace noomitted label nobase se ///
order( *partymean_env_diff* *partymean_lr_diff* *canddiff_partydiff_env* *canddiff_partydiff_lr*) star(+ 0.1 * 0.05 ** 0.01 *** 0.001)





